const code = `
require("module1");
const x = require("module2");
const y = require('module3');
const z = require("module4");
`;

const regex = /require\(["']([^"']+)["']\)/g;
let matches;
const result = [];

while ((matches = regex.exec(code)) !== null) {
  result.push(matches[1]);
}

console.log(result);